package com.yanze.customviewdemo.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class MyLocationMark extends View {
    private Paint mCirclePaint, mFillPaint, mSweepPaint;
    private float mRadius = 30;
    private float mSweepCurrRadius = mRadius + 2;
    private float mSweepRadius = mRadius + 30;

    private static final int COLOR_SWEEP = Color.parseColor("#6B0890C6");
    private static final int COLOR_NORMAL = Color.parseColor("#00A854");

    public MyLocationMark(Context context) {
        this(context, null);
    }

    public MyLocationMark(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyLocationMark(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mFillPaint = new Paint();
        mFillPaint.setColor(COLOR_NORMAL);
        mFillPaint.setStyle(Paint.Style.FILL);

        mCirclePaint = new Paint();
        mCirclePaint.setColor(Color.WHITE);
        mCirclePaint.setStrokeWidth(3);
        mCirclePaint.setAntiAlias(true);
        mCirclePaint.setStyle(Paint.Style.STROKE);

        mSweepPaint = new Paint(mFillPaint);
        mSweepPaint.setColor(Color.RED);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int height = (int) mSweepRadius * 2;
        int width = (int) mSweepRadius * 2;
        setMeasuredDimension(width, height);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(getWidth() / 2, getHeight() / 2);
        mSweepPaint.setColor(COLOR_SWEEP);
        if (mSweepCurrRadius < mSweepRadius) {
            mSweepCurrRadius += 2;
            canvas.drawCircle(0, 0, mSweepCurrRadius, mSweepPaint);
            postInvalidateDelayed(64);
        }else{
            mSweepCurrRadius = mRadius + 2;
            postInvalidateDelayed(100);
        }
        canvas.drawCircle(0, 0, mRadius - 3, mFillPaint);
        canvas.drawCircle(0, 0, mRadius - 3, mCirclePaint);
    }

    static final String minor = "480886";
    static final String rssi = "-90";
}
